﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Micua.Utility;

namespace Micua.UnitTest.Utility
{
    [TestClass]
    public class EncryptExtensionTester
    {
        [TestMethod]
        public void Single()
        {
            string encryptStr = "iceStone".EncryptStr();
            Console.WriteLine(encryptStr);

            var decryptStr = encryptStr.DecryptStr();

            Assert.AreEqual("iceStone", decryptStr);
        }

        [TestMethod]
        public void Multiple()
        {
            //var random=new Random(Guid.NewGuid().GetHashCode());
            for (int i = 0; i < 10; i++)
            {
                var str = RandomHelper.GetString(10);
                Console.WriteLine("原字符串：{0}\r\n", str);

                string encryptStr1 = str.EncryptStr();
                Console.WriteLine("第一次加密：{0}\r\n", encryptStr1);
                string encryptStr2 = str.EncryptStr();
                Console.WriteLine("第二次加密：{0}\r\n", encryptStr2);
                string encryptStr3 = str.EncryptStr();
                Console.WriteLine("第三次加密：{0}\r\n", encryptStr3);

                var decryptStr1 = encryptStr1.DecryptStr();
                Console.WriteLine("第一次解密：{0}\r\n", decryptStr1);
                Assert.AreEqual(str, decryptStr1);

                var decryptStr2 = encryptStr1.DecryptStr();
                Console.WriteLine("第二次解密：{0}\r\n", decryptStr2);
                Assert.AreEqual(str, decryptStr2);

                var decryptStr3 = encryptStr1.DecryptStr();
                Console.WriteLine("第三次解密：{0}\r\n", decryptStr3);
                Assert.AreEqual(str, decryptStr3);

                //测试通过

            }
        }

        [TestMethod]
        public void MixAndClear()
        {
            //var str1 = "sdfasdfsdsdfsdfsdfasdfa";
            //var mStr1 = EncryptExtension.MixUp(str1);
            //Console.WriteLine("{0}\r\n{1}",str1,mStr1);

            var str1 = "ddHHmmssfffmoremoremoremore";
            var mStr1 = EncryptExtension.MixUp(str1);
            Console.WriteLine("{0}\r\n{1}", str1, mStr1);

            var cStr1 = EncryptExtension.ClearUp(mStr1);
            Console.WriteLine("{0}\r\n{1}", str1, cStr1);
            Assert.AreEqual(str1, cStr1);

            var str2 = "yyyyMMddHHmmssfff";
            var mStr2 = EncryptExtension.MixUp(str2);
            Console.WriteLine("{0}\r\n{1}", str2, mStr2);

            var cStr2 = EncryptExtension.ClearUp(mStr2);
            Console.WriteLine("{0}\r\n{1}", str2, cStr2);
            Assert.AreEqual(str2, cStr2);

            var str3 = "ddHHmmss";
            var mStr3 = EncryptExtension.MixUp(str3);
            Console.WriteLine("{0}\r\n{1}", str3, mStr3);

            var cStr3 = EncryptExtension.ClearUp(mStr3);
            Console.WriteLine("{0}\r\n{1}", str3, cStr3);
            Assert.AreEqual(str3, cStr3);

            //时间戳混淆测试通过 2014年1月12日 00:49:46 By iceStone

        }

        [TestMethod]
        public void MyTestMethod()
        {
            var md5 = "123456".Md5();
            Assert.AreEqual(md5.Length,32);
        }
    }
}
